<?php
/*
 * Copyright 2009 Chen Ze <http://chenze.name/>
 *
 *
 * @License BSD 
 *
 */

require_once dirname(__FILE__).'/HttpDriverInterface.php';
class HttpDriverCurl implements HttpDriverInterface  { 
    private $curl;
    public function __construct() {
        $this->curl = curl_init();
    }
    public function setUrl($url) {
        curl_setopt($this->curl, CURLOPT_URL, $url);
    }
    public function setMethod($method) {
        if (httpreq::METHOD_GET==$method) {
            curl_setopt($this->curl, CURLOPT_HTTPGET, true);
        } else if (httpreq::METHOD_POST==$method) {
            curl_setopt($this->curl, CURLOPT_POST, true);
        }
    }
    public function setHeaders($headers) {
        curl_setopt($this->curl, CURLOPT_HTTPHEADER, $headers);
    }
    public function send() {
        curl_setopt($this->curl, CURLOPT_HEADER, true);
        curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
        return curl_exec($this->curl);
    }
}
